package com.yf.ability.config.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yf.ability.config.dto.CfgBannerDTO;
import com.yf.ability.config.service.CfgBannerService;
import com.yf.base.api.api.ApiRest;
import com.yf.base.api.api.controller.BaseController;
import com.yf.base.api.api.dto.BaseIdReqDTO;
import com.yf.base.api.api.dto.BaseIdsReqDTO;
import com.yf.base.api.api.dto.PagingReqDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* <p>
* 轮播图控制器
* </p>
*
* @author 聪明笨狗
* @since 2022-11-18 10:37
*/
@Api(tags={"轮播图"})
@RestController
@RequestMapping("/api/sys/config/banner")
public class CfgBannerController extends BaseController {

    @Autowired
    private CfgBannerService baseService;

    /**
    * 添加或修改
    * @param reqDTO
    * @return
    */
    @RequiresPermissions(value = {"sys:banner:add", "sys:banner:update"}, logical = Logical.OR)
    @ApiOperation(value = "添加或修改")
    @PostMapping("/save")
    public ApiRest save(@RequestBody CfgBannerDTO reqDTO) {
        baseService.save(reqDTO);
        return super.success();
    }

    /**
    * 批量删除
    * @param reqDTO
    * @return
    */
    @RequiresPermissions("sys:banner:delete")
    @ApiOperation(value = "批量删除")
    @PostMapping("/delete")
    public ApiRest delete(@RequestBody BaseIdsReqDTO reqDTO) {
        //根据ID删除
        baseService.delete(reqDTO.getIds());
        return super.success();
    }

    /**
    * 查找详情
    * @param reqDTO
    * @return
    */
    @ApiOperation(value = "查找详情")
    @PostMapping("/detail")
    public ApiRest<CfgBannerDTO> detail(@RequestBody BaseIdReqDTO reqDTO) {
        CfgBannerDTO dto = baseService.detail(reqDTO.getId());
        return super.success(dto);
    }

    /**
    * 分页查找
    * @param reqDTO
    * @return
    */
    @ApiOperation(value = "分页查找")
    @PostMapping("/paging")
    public ApiRest<IPage<CfgBannerDTO>> paging(@RequestBody PagingReqDTO<CfgBannerDTO> reqDTO) {

        //分页查询并转换
        IPage<CfgBannerDTO> page = baseService.paging(reqDTO);
        return super.success(page);
    }

}
